﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;

public partial class Property_Info_Discussion : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        
        if (Request.IsAuthenticated)
        {
           
            BindData();
           // messageBox.Text = this.Master.PropertyID.ToString();
        }
        else
        {
            Label1.Text = "Please sign in";
        }
    }

    void BindData()
    {
       
        Social_Discussion sc = new Social_Discussion();
        DataSet ds = sc.BindData(this.Master.PropertyID);
        commentsView.DataSource = ds;
        commentsView.DataBind();
   

        if (commentsView.Rows.Count == 0)
        {
            Label1.Text += " (No messages about this property yet)";
            //messageBox.Text = "No messages about this property yet";

        }
        else 
        {
            //messageBox.Text = "";
            Label1.Text = "Discussion";
        }
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        
        if (!Request.IsAuthenticated)
        {
            Label1.Text = "Please sign in to post comments";
            return;
        }
        else if (messageBox.Text != "")
        {
            Social_Discussion sc = new Social_Discussion();
            sc.PostComment(this.Master.PropertyID, messageBox.Text);
            Page.Response.Redirect(Page.Request.Url.ToString(), true);
        }
    }


    protected void commentsView_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            string decodedText = HttpUtility.HtmlDecode(e.Row.Cells[0].Text);
            e.Row.Cells[0].Text = decodedText;
        }

    }
    protected void commentsView_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        BindData();
        commentsView.PageIndex = e.NewPageIndex;
        commentsView.DataBind();
    }
}